﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using Communergy.Common;

namespace Communergy.Repository.EntityFramework
{
    public class EntityRepositoryFactory : IRepositoryFactory
    {
        #region IRepositoryFactory Members
        public IRealtimeRepository CreateRealtimeRepository(IUnitOfWork unitOfWork)
        {
            //TODO Entity Repository connection strings
            
            IRealtimeRepository repository = new EntityRealtimeRepository(unitOfWork);
            return repository;
        }

        public IHistoricRepository CreateHistoricRepository(IUnitOfWork unitOfWork)
        {
            var connString = ConfigurationManager.ConnectionStrings["communergyEntities"].ConnectionString;
            IHistoricRepository repository = new EntityHistoricRepository(unitOfWork);
            return repository;
        }

        public IMeterRepository CreateMeterRepository(IUnitOfWork unitOfWork)
        {
            var connString = ConfigurationManager.ConnectionStrings["communergyEntities"].ConnectionString;
            IMeterRepository repository = new EntityMeterRepository(unitOfWork);
            return repository;
        }
              
        //TODO Entity Framework unit of work
        public IUnitOfWork CreateUnitOfWork()
        {
            var connString = ConfigurationManager.ConnectionStrings["communergyEntities"].ConnectionString;
            var unitOfWork = new communergyEntities(connString);
            return unitOfWork;
        }

        #endregion

     
    }
}
